<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>

<head>
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css">
    <script src="${ctx}/layui/jquery.js"></script>
</head>

<body>
<div class="layui-card layui-anim layui-anim-upbit">
    <div class="layui-card-header">
        <a onclick="prev()"><i class="layui-icon layui-icon-left"></i></a>
        <span style="font-size: 20px;">假期申请单</span>
        <span style="float: right"> <a onclick="refresh()"><i class="layui-icon layui-icon-refresh"></i></a></span>
    </div>
    <div class="layui-card-body">

        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input name="title" class="layui-input" lay-verType="tips"></input>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <select name="type">
                        <option></option>
                        <option value="1">事假</option>
                        <option value="2">病假</option>
                        <option value="3">其他</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">原因</label>
                <div class="layui-input-block">
                    <textarea name="cause" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">地点</label>
                <div class="layui-input-block">
                    <input name="location" type="location" class="layui-input" lay-verType="tips"></input>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-block">
                    <!-- <div id="startTime"></div> -->
                    <input name="startTime" class="layui-input" type="text" id="startTime">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-block">
                    <!-- <div id="startTime"></div> -->
                    <input name="endTime" class="layui-input" type="text" id="endTime">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button lay-submit class="layui-btn layui-btn-normal" lay-filter="ff">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

    </div>
</div>


</body>
<script src="${ctx}/layui/layui.all.js"></script>
<script>
    layui.use(['form', 'element', 'laydate'], function () {
        var form = layui.form;
        var laydate = layui.laydate;
        form.on("submit(ff)", data => {
            var index = null;
            $.ajax({
                url: "${ctx}/apply/addOne",
                type: "post",
                dataType: "json",
                contentType: "application/json",
                data: JSON.stringify(data.field),
                beforeSend: function (request) {
                    index = layer.load();
                },
                success: res => {
                    layer.close(index)
                    if (res.code == 1) {
                        layer.alert('申请成功', {
                            skin: 'layui-layer-molv' //样式类名
                            , closeBtn: 0
                        }, function () {
                            window.location.href = "${ctx}/apply/appListPage"
                        });
                    } else {
                        layer.msg(res.msg)
                    }
                },
                error: res => {
                    layer.close(index)
                    alert(res.msg)
                }
            })

            return false;
        })
        laydate.render({
            elem: '#startTime'
        });
        laydate.render({
            elem: '#endTime'
        });
        // laydate.render({
        //     elem: '#startTime',
        //     position: 'static',

        //     calendar: true,

        // });
    })
</script>
<script>
    function prev() {
        history.go(-1);
    }

    function refresh() {
        window.location.reload()
    }
</script>
</html>
